<!DOCTYPE html>
<html>
<head>
    <title>微信支付</title>
    <% include common/meta.ejs %>
    <% include common/public.ejs %>
    <style>
        .weui_cell:before {
            left: 0;
        }
    </style>
</head>
<body ontouchstart>
<div style="text-align: center; margin-top: 50px;" id="errorMsg"><%= data.code %></div>
<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js" type="text/javascript"></script>
<% include common/footer.ejs %>
<script type="text/javascript">
    wx.config({
        debug: false,
        appId: "<%= data.appId %>", // 必填，公众号的唯一标识
        timestamp: "<%= data.timestamp %>",
        nonceStr: "<%= data.nonceStr %>",
        signature: "<%= data.signature %>",
        jsApiList: [  // 必填，需要使用的JS接口列表
            "onMenuShareTimeline",
            "onMenuShareAppMessage",
            "getNetworkType",
            "chooseWXPay"
        ]
    });
    wx.ready(function () {
        wx.chooseWXPay({
            timestamp: "<%= data.timestamp %>", // 支付签名时间戳
            nonceStr: "<%= data.nonceStr %>", // 支付签名随机串
            package: "<%= data.package %>", // 统一支付接口返回的package包
            signType: "<%= data.signType %>", // 签名方式，'MD5'
            paySign: "<%= data.paySign %>", // 支付签名
            success: function (res) {
                Dolphin.ajax({
                    url:CTX+'/api/4a115bfd4a754bb6a14bb074f0dd7a64',
                    type:'post',
                    forceUrl:'true',
                    data: Dolphin.json2string({
                        id:'<%= data.id %>',
                    }),
                    onSuccess:function () {
//                        location.href = CTX+"/view/account";
                    }
                });
            },
            complete: function (res) {
                if(res.errMsg.indexOf('ok')>-1){
                    $("#errorMsg").html("支付成功  3秒后跳转至个人信息");
                    setTimeout(function () {
                        location.href = CTX+"/view/account";
                    }, 3000);
                } else if(res.errMsg.indexOf('cancel')>-1){
                    $("#errorMsg").html("支付已取消");
                } else {
                    $("#errorMsg").html("支付失败" + res.errMsg);
                }
            },
            fail: function (res) {
                $("#errorMsg").html("支付失败" + res.errMsg);
            }
        });
    });
    wx.error(function (res) {
    });

</script>
</body>
</html>
